home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 003-desktop.lzm / usr / bin / khc_mansearch.pl < prev    next >
Encoding:
Perl Script  |  2007-01-15  |  2.0 KB  |  85 lines

  1. #!/usr/bin/perl
  2. #
  3. #  Script for searching man pages. The result is generated as HTML.
  4. #
  5. #  This file is part of KHelpcenter.
  6. #
  7. #  Copyright (C) 2002  SuSE Linux AG, Nuernberg
  8. #
  9. #  Author: Cornelius Schumacher <cschum@suse.de>
  10. #
  11. #  This program is free software; you can redistribute it and/or modify
  12. #  it under the terms of the GNU General Public License as published by
  13. #  the Free Software Foundation; either version 2 of the License, or
  14. #  (at your option) any later version.
  15. #
  16. #  This program is distributed in the hope that it will be useful,
  17. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. #  GNU General Public License for more details.
  20. #
  21. #  You should have received a copy of the GNU General Public License
  22. #  along with this program; if not, write to the Free Software
  23. #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  24.  
  25. use strict;
  26.  
  27. use Getopt::Long;
  28.  
  29. my ( $words, $maxcount, $lang, $help );
  30.  
  31. GetOptions (
  32.   'maxcount=s' => \$maxcount,
  33.   'words=s' => \$words,
  34.   'lang=s' => \$lang,
  35.   'help' => \$help
  36. );
  37.  
  38. if ( $help ) {
  39.   print STDERR "Usage: khc_mansearch.pl --maxcount=n --words=<string> " .
  40.     "--lang=<languagecode>\n";
  41.   exit 1;
  42. }
  43.  
  44. if ( !$words ) {
  45.   print STDERR "No search words given.\n";
  46.   exit;
  47. }
  48.  
  49. # Perform search
  50. if ( !open( MAN, "-|", "apropos", $words ) ) {
  51.   print "Can't open apropos.\n";
  52.   exit 1;
  53. }
  54. my @results;
  55. while( <MAN> ) {
  56. #  print "RAW:$_";
  57.   chop;
  58.   /^([^\s]+)\s+\((.*)\)\s+-\s+(.*)$/;
  59.   my $page = $1;
  60.   my $section = $2;
  61.   my $description = $3;
  62.  
  63.   if ( $page ) { push @results, [ $page, $section, $description ]; }
  64. }
  65. close MAN;
  66.  
  67. my $nummatches = @results;
  68.  
  69. if ( $nummatches > 0 ) {
  70.   print "<ul>\n";
  71.  
  72.   my $count = 0;
  73.   for my $result ( @results ) {
  74.     my ( $page, $section, $description ) = @$result;
  75.     my $url = "man:" . $page;
  76.     print "<li><a href=\"$url\">";
  77.     print "$page - $description</a></li>\n";
  78.     if ( ++$count == $maxcount ) { last; }
  79.   }
  80.  
  81.   print "</ul>\n";
  82. }
  83.  
  84. 1;
  85.